package castle.defense.project;

import android.content.Context;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

/**
 * Basic View object to hold the menu screen
 * @author Daniel Wasserman
 *
 */
public class MenuView extends SurfaceView implements SurfaceHolder.Callback, OnTouchListener {
	MenuThread thread;
	public MenuView(Context context) {
		super(context);
		SurfaceHolder s = this.getHolder();
		s.addCallback(this);
		this.setFocusable(true);
		thread = new MenuThread(context);
		this.setOnTouchListener(this);
	}
	
	public boolean onTouch(View v, MotionEvent e) {
		//on-down
		if(e.getAction()==MotionEvent.ACTION_DOWN) {
			thread.onDown(e);
		}
		return false;
	}

	public void surfaceChanged(SurfaceHolder s, int format, int width, int height) {
		thread.setSurfaceHolder(s);
		PE.setBounds(s.getSurfaceFrame().width(), s.getSurfaceFrame().height());
	}

	public void surfaceCreated(SurfaceHolder s) {
		PE.setBounds(s.getSurfaceFrame().width(), s.getSurfaceFrame().height());
		GraphicsEngine.initialize();
		thread.setSurfaceHolder(s);
		thread.start();
	}

	public void surfaceDestroyed(SurfaceHolder s) {
		thread.setRunning(false);
	}
	
	public void stop() {
		thread.setRunning(false);
	}
}
